import { defineStore } from 'pinia'

const userInfo = {
	id: '',
	username: '',
	email: '',
	role: 'USER' // 设置默认角色
}

export const userStore = defineStore('user', {
	state: () => ({
		user: { ...userInfo }
	}),
	getters: {
		isAdmin: (state) => state.user.role === 'ADMIN'
	},
	actions: {
		setUser(user) {
			const { id, username, email, role } = user
			this.user = { id, username, email, role }
		}
	},
	persist: true
})